﻿
@{
    ViewData["Title"] = "Apply";
    Layout = "~/Areas/Admin/Views/Shared/_VueLayout.cshtml";
    var paraPlatForm = ViewData["platForm"];
    
}


@section header{
    <style>
        .handle-box {
            margin-bottom: 20px;
        }

        .handle-select {
            width: 120px;
        }

        .handle-input {
            width: 300px;
            display: inline-block;
        }

        .table {
            width: 100%;
            font-size: 14px;
        }

        .red {
            color: #ff0000;
        }

        .mr10 {
            margin-right: 10px;
        }

        .table-td-thumb {
            display: block;
            margin: auto;
            width: 40px;
            height: 40px;
        }

        /*表单*/
        .el-form-item {
            width: 23%
        }


        .el-dialog__title {
            color: antiquewhite
        }

        .bootstrap-elem-field {
            margin-bottom: 10px;
            padding: 10px;
            /*padding-top: 10px;*/
            border-width: 1px;
            border-style: solid;
            border-color: #e6e6e6;
        }

            .bootstrap-elem-field legend {
                margin-left: 20px;
                padding: 0 10px;
                font-size: 16px;
                font-weight: 300;
                border-bottom: none;
                width: auto;
            }

        .bootstrap-field-box {
            padding: 10px 15px;
        }

        .el-table__body tr.current-row > td {
            background-color: #f5dc6f !important;
        }
    </style>
}
<div id="app" v-cloak>
    <div id='wrapper'>


        <div class="container">

            <el-card class="box-card" style="margin-bottom:10px;">
                <div slot="header" class="clearfix">
                    <i class="el-icon-s-order" >{{title1}}</i>
                </div>

                <div class="handle-box">
                    <el-select v-model="itemId" placeholder="产品" v-on:change="itemChange">
                        <el-option v-for="item in itemList"
                                   :key="item.value"
                                   :label="item.label"
                                   :value="item.value">
                        </el-option>
                    </el-select>
                    <el-input-number v-model="totalAmount" class='handle-input mr10' placeholder="请输入广告收益......"></el-input-number>

                    <el-button type="primary" v-on:click="handleCalc">计算</el-button>
                    <el-button type="danger" v-on:click="handleBack">撤销</el-button>

                </div>


                <el-table v-loading="loading" highlight-current-row :data="visitInfo" style="width: 100%;margin-bottom: 20px;"
                          row-key="id" border>

                    <el-table-column prop="begTime" fixed="left" label="开始时间">
                    </el-table-column>
                    <el-table-column prop="endTime" fixed="left" label="当前时间">
                    </el-table-column>
                    <el-table-column prop="timeLen" fixed="left" label="时长(小时)">
                    </el-table-column>
                    <el-table-column prop="visitCount" fixed="left" label="总访问次数">
                    </el-table-column>
                    <el-table-column prop="finishCount" fixed="left" label="总完成次数">
                    </el-table-column>

                </el-table>

            </el-card>


            <el-card class="box-card">
                <div slot="header" class="clearfix">
                    <i class="el-icon-s-order">分销商收益情况</i>
                </div>

                <el-table v-loading="loading1" :data="tableData" highlight-current-row>
                    <el-table-column prop="agentName"
                                     label="分销商">
                    </el-table-column>
                    <el-table-column prop="itemName"
                                     label="产品名">
                    </el-table-column>
                    <el-table-column prop="visitCount"
                                     label="访问次数">
                    </el-table-column>
                    <el-table-column prop="finishCount"
                                     label="完成次数">
                    </el-table-column>
                    <el-table-column prop="perAmount"
                                     label="单次收益">
                    </el-table-column>
                    <el-table-column prop="profit"
                                     label="今日收益">
                    </el-table-column>
                    <el-table-column prop="profitDate"
                                     label="结算时间">
                    </el-table-column>

                </el-table>
                <div class="pagination" style="text-align: center;">
                    <el-pagination background v-on:current-change="handleCurrentChange" v-on:size-change='handleSizeChange' :current-page.sync="queryModel.pageModel.page" :page-sizes="[10, 20, 50, 80]"
                                   :page-size.sync="queryModel.pageModel.rows" layout="total,sizes, prev, pager, next" :total="total">
                    </el-pagination>

                </div>
            </el-card>


        </div>

    </div>

</div>

@section footer{
<script type="text/javascript">

        var vue = new Vue({
            el: "#app",
            data: {
                loading: false,
                loading1: false,
                queryModel: {
                    batch:"",
                    pageModel: {
                        page: 1,
                        rows: 5
                    }
                },
                platForm: @((string)ViewData["platForm"]),
                itemId: "",
                settleFlag: "0",
                totalAmount:0,
                tableData: [],
                visitInfo:[],
                itemList: [],
                total: 0,
                title1:"",
                currentTableModel: {},
                currentLineModel: {

                }


            },
            created() {
                var that = this;
                this.getItemList()
                //this.getOutBoundTypeList();
                console.log("this.platForm==" + this.platForm);
                console.log("this.platForm==11" + this.platForm=="1");
                if (this.platForm=="1") this.title1 = "【抖音平台】推广收益计算";
                else if (this.platForm == "2") this.title1 = "【微信平台】推广收益计算";
                else if (this.platForm == "3") this.title1 = "【快手平台】推广收益计算";
            },
            methods: {

                itemChange: function (val) {
                    var that = this;
                    request.post("/biz/itempromotion/QueryItemPromotionTotalCountInfo", { settleFlag: "0", itemId: val }).then(function (res) {

                        var list = [];
                        list.push(res.data.data);
                        that.visitInfo = list;
                        //var timelen = res.data.data.timeLen;
                    });
                },
                getItemList: function () {//获取站台列表
                    var that = this;
                    request.post("/biz/itempromotion/queryUnsettleItemList", {platForm:@ViewData["platForm"]}).then(function (res) {
                        that.itemList = res.data;
                    });
                },
                handleCalc: function () {
                    var that = this;
                    if (that.itemId=="") {
                        this.$message.warning("请选择需要计算收益的产品！");
                        return;
                    }
                    if (that.totalAmount == 0) {
                        this.$message.warning("请填写产品今日广告收益！");
                        return;
                    }
                    if (that.queryModel.batch != "") {
                        request.post("/biz/profit/checkIsSettle", { itemId: that.itemId, batch: that.queryModel.batch, auditFlag: "10" }).then(function (res) {
                            console.log(res.data);
                            that.loading = false;
                            //var batchcode = res.data;
                            if (res.data.code != 1) {
                                that.$message.warning(res.data.msg);
                                return;
                            }
                            that.calcProfit();
                        });
                    } else {
                        that.calcProfit();
                    }
                },
                calcProfit: function () {
                    var that = this;
                    this.$confirm('请确认所填广告收益金额是否正确，确认后点继续？', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        that.loading = true;
                        request.post("/biz/profit/CalcAndInserProfitAsync", { itemId: that.itemId, totalAmount: that.totalAmount }).then(function (res) {
                            console.log(res.data);
                            that.loading = false;
                            //var batchcode = res.data;
                            if (res.data.code == 1) {
                                //that.$message.success(res.data.msg);
                                that.queryModel.batch = res.data.data;
                                that.getDatas();
                            } else {
                                that.$message.warning(res.data.msg);
                            }

                        });
                    });
                },
                getDatas: function () {
                    var that = this;
                    that.loading1 = true;
                    request.post("/biz/profit/QueryCalcResult", that.queryModel).then(function (res) {
                        console.log(res.data);
                        that.loading1 = false;

                        that.tableData = res.data.data.rows;

                        that.total = res.data.data.total;
                    });
                },
                handleBack: function () {
                    var that = this;

                    this.$confirm('确定将该产品分销计算结果撤销吗？是否继续？', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {

                        request.post("/biz/profit/CalcResultRollBack", { batch: that.queryModel.batch, itemId: that.itemId }).then(function (res) {
                            console.log(res.data);
                            if (res.data.code == 1) {
                                that.$message.success(res.data.msg);
                            } else {
                                that.$message.warning(res.data.msg);
                            }

                            that.getDatas();
                        });
                    });
                },
                handleSearch: function () {//查询
                    this.getDatas();
                },
                handleCurrentChange: function (index) {
                    this.queryModel.pageModel.page = index;
                    this.getDatas();
                },
                handleSizeChange: function () {
                    this.getDatas();

                }
            }
        });

</script>
}
